<meta charset="UTF-8"/>

<?php

$filename = 'user.dat';

$name = $_POST['name'];
$pwd = $_POST['pwd'];
$rem = empty($_POST['rem']);

$uses = array();
//***************************
$struser = file_get_contents($filename);
//$struser = "tom\t123\nlilei\tabc\n";
$usersstr = explode("\n", $struser);
foreach ($usersstr as $v) {
	$temp = explode("\t", $v);
	if (count($temp) == 2) {
		$tempname = $temp[0];
		$temppwd = $temp[1];
		$uses[$tempname] = $temppwd;
	}
}

//***************************

if (isset($uses[$name]) && $uses[$name] == $pwd) {
	session_start();
	$_SESSION['user'] = $name;

	if (!$rem) {
		setcookie('user', $name, time() + (60 * 60 * 24 * 7));
		setcookie('pwd', $pwd, time() + (60 * 60 * 24 * 7));
	}

	//echo '<meta http-equiv="refresh" content="2;url=list.php"/>';
	echo '登陆成功！';
} else {
	//echo '<meta http-equiv="refresh" content="2;url=index.php"/>';
	echo '登陆失败！';
}
?>